package com.base.controller;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.base.comm.CommContent;
import com.base.po.voip.Withdrawals;
import com.base.service.LogsService;
import com.base.service.WithdrawalsService;
import com.base.utils.IP;

/**
 * 修改提现记录信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class update_Withdraw {

	@Autowired
	private LogsService logsService; // log日志
	@Autowired
	private WithdrawalsService withdrawalsService; // 提现信息

	// 修改提现记录信息
	@RequestMapping(value = "/toupdateWithdraw", method = RequestMethod.POST)
	public @ResponseBody int toupdateWithdraw(HttpServletRequest request, @RequestBody JSONObject obj) throws Exception {
		String id = obj.get("id").toString();
		String status = obj.get("status") == null ? null : obj.get("status").toString();
		String datastatus = obj.get("datastatus") == null ? null : obj.get("datastatus").toString();
		if (request.getSession().getAttribute("adminUserId") == null) return -1; // 未登录
		Withdrawals withdrawals = new Withdrawals();
		withdrawals.setId(id);
		withdrawals.setStatus(Integer.parseInt(status));
		withdrawals.setDatastatus(datastatus);
		logsService.insert(CommContent.TYPE_UPDATE, CommContent.LOGS_UPDATE + "改动提现记录状态",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request)); // 记录修改日志
		return withdrawalsService.updateByPrimaryKeySelective(withdrawals); // 修改
	}
}
